package Queue;

public class MyQueue {
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    private ListNode front;
    private ListNode rear;
    private int usedSize;
    public void offer(int x){
        ListNode node = new ListNode(x);
        if (front == null){
            front = rear = node;
        }else {
            node.next = front;
            front.prev = node;
            front = node;

        }
        usedSize++;
    }

    public int poll(){
        int ret = rear.val;
       if (front == null){
           return -1;
       }
       if (front == rear){
           front = null;
           rear = null;
           usedSize--;
           return ret;
       }
       rear = rear.prev;
       rear.next =null;
       usedSize--;
        return ret;
    }
    public int peek() {
        if (front == null) {
            return -1;
        }
        return front.val;
    }
    public int getUsedSize(){
        return usedSize;
    }
    public boolean isEmpty(){
        return usedSize == 0;
    }
}
